package com.bp.hearthealth.pulse.lnapps.bp_ui.bp_dialog

import android.app.Activity
import android.app.Dialog
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import androidx.databinding.DataBindingUtil
import com.bp.hearthealth.pulse.lnapps.R
import com.bp.hearthealth.pulse.lnapps.bp_extension.UIHelperBp
import com.bp.hearthealth.pulse.lnapps.bp_utils.Constants
import com.bp.hearthealth.pulse.lnapps.bp_utils.DoubleClickListener
import com.bp.hearthealth.pulse.lnapps.databinding.BloodPressureDetailLayoutBgBinding

class BpBloodPressureDetailDialog(context: Activity) {
    private lateinit var binding: BloodPressureDetailLayoutBgBinding
    private lateinit var dialog: Dialog
    private val activity: Activity = context

    fun showDialog() {
        dialog = Dialog(activity, R.style.My_Dialog_FullScreen)
        binding = DataBindingUtil.inflate(LayoutInflater.from(activity),
            R.layout.blood_pressure_detail_layout_bg,
            null,
            false)
        binding.root.let { dialog.setContentView(it) }//核心代码
        dialog.setCanceledOnTouchOutside(false)
        dialog.setCancelable(false)
        val lp = dialog.window?.attributes
        lp?.width = WindowManager.LayoutParams.MATCH_PARENT
        lp?.height = WindowManager.LayoutParams.WRAP_CONTENT

        lp?.alpha = 1f
        dialog.window?.attributes = lp
        if (activity.isFinishing) {
            return
        }
        dialog.show()
        binding.tvOk.setOnClickListener(object : DoubleClickListener() {
            override fun onNoDoubleClick(v: View?) {
                dialog.dismiss()
            }
        })
        initView()
    }

    private fun initView() {
        binding.apply {
            includeHypotensive.apply {
                ivColor.setImageResource(R.drawable.dot_hypotensive_bp)
                tvTypeTitle.text = UIHelperBp.getString(R.string._hypotensive_str)
                tvTvTypeSize.text = Constants.HYPOTENSIVE_SIZE
            }
            includeNormal.apply {
                ivColor.setImageResource(R.drawable.dot_normal_bp)
                tvTypeTitle.text = UIHelperBp.getString(R.string._normal_str)
                tvTvTypeSize.text = Constants.NORMAL_SIZE
            }
            includeElevated.apply {
                ivColor.setImageResource(R.drawable.dot_elevated_bp)
                tvTypeTitle.text = UIHelperBp.getString(R.string._elevated_str)
                tvTvTypeSize.text = Constants.ELEVATED_SIZE
            }
            includeStage1.apply {
                ivColor.setImageResource(R.drawable.dot_stage_1_bp)
                tvTypeTitle.text = UIHelperBp.getString(R.string._hypotensive_stage_1_str)
                tvTvTypeSize.text = Constants.STAGE1_SIZE
            }
            includeStage2.apply {
                ivColor.setImageResource(R.drawable.dot_stage_2_bp)
                tvTypeTitle.text = UIHelperBp.getString(R.string._hypotensive_stage_2_str)
                tvTvTypeSize.text = Constants.STAGE2_SIZE
            }
            includeCrisis.apply {
                ivColor.setImageResource(R.drawable.dot_crisis_bp)
                tvTypeTitle.text = UIHelperBp.getString(R.string._hypotensive_crisis_str)
                tvTvTypeSize.text = Constants.CRISIS_SIZE
            }
        }
    }
}
